﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Duoease.ContainerModel.Entity;
using Duoease.ContainerModel.Utils;

namespace Duoease.ContainerModel
{
    public partial class EditModel : Form
    {
        private BaseModel baseModel = new BaseModel();
        private ShelfModel DModel = new ShelfModel();
        private BoxModel BModel = new BoxModel();
        ContainerModelView model = new ContainerModelView();
        int style = 0;
        string ID = "";
        public EditModel(ContainerModelView _model, string _ID, int _style)
        {
            InitializeComponent();
            model = _model;
            style = _style;
            ID = _ID;
        }

        private void EditModel_Load(object sender, EventArgs e)
        {
            TextBoxID.Text = ID;
        }

        private void SaveBtn_Click(object sender, EventArgs e)
        {

            switch (style)
            {
                case 1:
                    DModel.ID = TextBoxID.Text.Trim();
                    DModel.Row = (int)m_numericRow.Value;
                    DModel.Column = (int)numericColumn.Value;
                    DModel.SurfaceColor = surfaceColorBtn.BackColor;
                    DModel.Alpha = (int)numericUpDown2.Value;
                    DModel.LineColor = LineColorBtn.BackColor;
                    DModel.LineWidth = (int)numericLineWidth.Value;
                    DModel.Title = TextBoxTip.Text;
                    model.ShelfModel = DModel;
                    model.shelfSpecification = ModelUtil.GetCodeNo((int)m_numericRow.Value) + ModelUtil.GetCodeNo((int)numericColumn.Value);
                    break;
                case 2:
                    BModel.ID = TextBoxID.Text.Trim();
                    BModel.Row = (int)m_numericRow.Value;
                    BModel.Column = (int)numericColumn.Value;
                    BModel.SurfaceColor = surfaceColorBtn.BackColor;
                    BModel.Alpha = (int)numericUpDown2.Value;
                    BModel.LineColor = LineColorBtn.BackColor;
                    BModel.LineWidth = (int)numericLineWidth.Value;
                    BModel.Title = TextBoxTip.Text;
                    model.BoxModel = BModel;
                    model.boxSpecification = ModelUtil.GetCodeNo((int)m_numericRow.Value) + ModelUtil.GetCodeNo((int)numericColumn.Value);
                    break;
                default:
                    break;
            }
            this.Close();

        }

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void surfaceColorBtn_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                surfaceColorBtn.BackColor = colorDialog1.Color;
            }
        }

        private void LineColorBtn_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                LineColorBtn.BackColor = colorDialog1.Color;
            }
        }

        private void ReviewBtn_Click_1(object sender, EventArgs e)
        {
            try
            {
                switch (style)
                {
                    case 1:
                        DModel.ID = TextBoxID.Text.Trim();
                        DModel.Row = (int)m_numericRow.Value;
                        DModel.Column = (int)numericColumn.Value;
                        DModel.SurfaceColor = surfaceColorBtn.BackColor;
                        DModel.Alpha = (int)numericUpDown2.Value;
                        DModel.LineColor = LineColorBtn.BackColor;
                        DModel.LineWidth = (int)numericLineWidth.Value;
                        DModel.Title = TextBoxTip.Text;
                        model.ShelfModel = DModel;
                        break;
                    case 2:
                        BModel.ID = TextBoxID.Text.Trim();
                        BModel.Row = (int)m_numericRow.Value;
                        BModel.Column = (int)numericColumn.Value;
                        BModel.SurfaceColor = surfaceColorBtn.BackColor;
                        BModel.Alpha = (int)numericUpDown2.Value;
                        BModel.LineColor = LineColorBtn.BackColor;
                        BModel.LineWidth = (int)numericLineWidth.Value;
                        BModel.Title = TextBoxTip.Text;
                        model.BoxModel = BModel;
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                MessageBox.Show("检查信息录入是否正确。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
